<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="访问日期" prop="fangwenriqi">
        <el-input
          v-model="queryParams.fangwenriqi"
          placeholder="请输入访问日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户标识" prop="yonghubiaoshi">
        <el-input
          v-model="queryParams.yonghubiaoshi"
          placeholder="请输入用户标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流量类型" prop="liuliangleixing">
        <el-input
          v-model="queryParams.liuliangleixing"
          placeholder="请输入流量类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="kaishishijian">
        <el-input
          v-model="queryParams.kaishishijian"
          placeholder="请输入开始时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结束时间" prop="jieshushijian">
        <el-input
          v-model="queryParams.jieshushijian"
          placeholder="请输入结束时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时长" prop="shichang">
        <el-input
          v-model="queryParams.shichang"
          placeholder="请输入时长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上行流量" prop="shangxingliuliang">
        <el-input
          v-model="queryParams.shangxingliuliang"
          placeholder="请输入上行流量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下行流量" prop="xiaxingliuliang">
        <el-input
          v-model="queryParams.xiaxingliuliang"
          placeholder="请输入下行流量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总流量" prop="zongliuliang">
        <el-input
          v-model="queryParams.zongliuliang"
          placeholder="请输入总流量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="源ip" prop="yuanip">
        <el-input
          v-model="queryParams.yuanip"
          placeholder="请输入源ip"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="目的ip" prop="mudiip">
        <el-input
          v-model="queryParams.mudiip"
          placeholder="请输入目的ip"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="源端口" prop="yuanduankou">
        <el-input
          v-model="queryParams.yuanduankou"
          placeholder="请输入源端口"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="目的端口" prop="mudiduankou">
        <el-input
          v-model="queryParams.mudiduankou"
          placeholder="请输入目的端口"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型名称" prop="chexingmingcheng">
        <el-input
          v-model="queryParams.chexingmingcheng"
          placeholder="请输入车型名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="查询次数" prop="queryNum">
        <el-input
          v-model="queryParams.queryNum"
          placeholder="请输入查询次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="访问日期" align="center" prop="fangwenriqi" />
      <el-table-column label="用户标识" align="center" prop="yonghubiaoshi" />
      <el-table-column label="流量类型" align="center" prop="liuliangleixing" />
      <el-table-column label="开始时间" align="center" prop="kaishishijian" />
      <el-table-column label="结束时间" align="center" prop="jieshushijian" />
      <el-table-column label="时长" align="center" prop="shichang" />
      <el-table-column label="上行流量" align="center" prop="shangxingliuliang" />
      <el-table-column label="下行流量" align="center" prop="xiaxingliuliang" />
      <el-table-column label="总流量" align="center" prop="zongliuliang" />
      <el-table-column label="源ip" align="center" prop="yuanip" />
      <el-table-column label="目的ip" align="center" prop="mudiip" />
      <el-table-column label="状态码" align="center" prop="status" />
      <el-table-column label="源端口" align="center" prop="yuanduankou" />
      <el-table-column label="目的端口" align="center" prop="mudiduankou" />
      <el-table-column label="网址、特征信息" align="center" prop="wangzhi" />
      <el-table-column label="车型名称" align="center" prop="chexingmingcheng" >
        <template slot-scope="scope">
          <div v-if="scope.row.chexingmingcheng" @click="showCXdialog(scope.row)" style="cursor: pointer;">
            {{ scope.row.chexingmingcheng }}
          </div>
          <div v-else class="no-click">
            无
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="浏览记录" align="center" prop="queryNum" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改dataInfo对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="访问日期" prop="fangwenriqi">
          <el-input v-model="form.fangwenriqi" placeholder="请输入访问日期" />
        </el-form-item>
        <el-form-item label="用户标识" prop="yonghubiaoshi">
          <el-input v-model="form.yonghubiaoshi" placeholder="请输入用户标识" />
        </el-form-item>
        <el-form-item label="流量类型" prop="liuliangleixing">
          <el-input v-model="form.liuliangleixing" placeholder="请输入流量类型" />
        </el-form-item>
        <el-form-item label="开始时间" prop="kaishishijian">
          <el-input v-model="form.kaishishijian" placeholder="请输入开始时间" />
        </el-form-item>
        <el-form-item label="结束时间" prop="jieshushijian">
          <el-input v-model="form.jieshushijian" placeholder="请输入结束时间" />
        </el-form-item>
        <el-form-item label="时长" prop="shichang">
          <el-input v-model="form.shichang" placeholder="请输入时长" />
        </el-form-item>
        <el-form-item label="上行流量" prop="shangxingliuliang">
          <el-input v-model="form.shangxingliuliang" placeholder="请输入上行流量" />
        </el-form-item>
        <el-form-item label="下行流量" prop="xiaxingliuliang">
          <el-input v-model="form.xiaxingliuliang" placeholder="请输入下行流量" />
        </el-form-item>
        <el-form-item label="总流量" prop="zongliuliang">
          <el-input v-model="form.zongliuliang" placeholder="请输入总流量" />
        </el-form-item>
        <el-form-item label="源ip" prop="yuanip">
          <el-input v-model="form.yuanip" placeholder="请输入源ip" />
        </el-form-item>
        <el-form-item label="目的ip" prop="mudiip">
          <el-input v-model="form.mudiip" placeholder="请输入目的ip" />
        </el-form-item>
        <el-form-item label="源端口" prop="yuanduankou">
          <el-input v-model="form.yuanduankou" placeholder="请输入源端口" />
        </el-form-item>
        <el-form-item label="目的端口" prop="mudiduankou">
          <el-input v-model="form.mudiduankou" placeholder="请输入目的端口" />
        </el-form-item>
        <el-form-item label="网址、特征信息" prop="wangzhi">
          <el-input v-model="form.wangzhi" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="车型名称" prop="chexingmingcheng">
          <el-input v-model="form.chexingmingcheng" placeholder="请输入车型名称" />
        </el-form-item>
        <!-- <el-form-item label="查询次数" prop="queryNum">
          <el-input v-model="form.queryNum" placeholder="请输入查询次数" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 车型跳转对话框 -->
    <el-dialog title="车辆详情" :visible.sync="cxDialogVisible" width="500px" v-if="code == 200">
      <el-form ref="carDetailsform" :model="carDetailsForm" :rules="rules" label-width="80px">
        <el-form-item label="品牌" prop="qichepinpai">
          <el-input v-model="carDetailsForm.qichepinpai" />
        </el-form-item>
        <el-form-item label="级别" prop="chrjibie">
          <el-input v-model="carDetailsForm.chrjibie" />
        </el-form-item>
        <el-form-item label="型号" prop="chexinghao">
          <el-input v-model="carDetailsForm.chexinghao" />
        </el-form-item>
        <el-form-item label="国别" prop="guobie">
          <el-input v-model="carDetailsForm.guobie" />
        </el-form-item>
        <el-form-item label="环保标准" prop="huanbaobiaozhun">
          <el-input v-model="carDetailsForm.huanbaobiaozhun" />
        </el-form-item>
        <el-form-item label="结构" prop="jiegou">
          <el-input v-model="carDetailsForm.jiegou" />
        </el-form-item>
        <el-form-item label="驱动" prop="qudong">
          <el-input v-model="carDetailsForm.qudong" />
        </el-form-item>
        <el-form-item label="排量" prop="pailiang">
          <el-input v-model="carDetailsForm.pailiang" />
        </el-form-item>
        <el-form-item label="能源" prop="nengyuan">
          <el-input v-model="carDetailsForm.nengyuan" />
        </el-form-item>
        <el-form-item label="指导价" prop="jingxiaoshangbaojia">
          <el-input v-model="carDetailsForm.jingxiaoshangbaojia" />
        </el-form-item>
        <el-form-item label="尺寸" prop="changkuangao">
          <el-input v-model="carDetailsForm.changkuangao" />
        </el-form-item>
        <el-form-item label="变速箱" prop="biansuxiang">
          <el-input v-model="carDetailsForm.biansuxiang" />
        </el-form-item>
        <el-form-item label="最大功率" prop="zuidagonglv">
          <el-input v-model="carDetailsForm.zuidagonglv" />
        </el-form-item>
        <el-form-item label="最高车速" prop="zuigaochesu">
          <el-input v-model="carDetailsForm.zuigaochesu" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="handleClose()">取 消</el-button> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, editDetails, getCarDetails } from "@/api/system/info";

export default {
  name: "Info",
  data() {
    return {
      cxDialogVisible: false,
      code: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // dataInfo表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fangwenriqi: null,
        yonghubiaoshi: null,
        liuliangleixing: null,
        kaishishijian: null,
        jieshushijian: null,
        shichang: null,
        shangxingliuliang: null,
        xiaxingliuliang: null,
        zongliuliang: null,
        yuanip: null,
        mudiip: null,
        status: null,
        yuanduankou: null,
        mudiduankou: null,
        wangzhi: null,
        chexingmingcheng: null,
        queryNum: null
      },
      // 详情列表
      carDetailsForm: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询dataInfo列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fangwenriqi: null,
        yonghubiaoshi: null,
        liuliangleixing: null,
        kaishishijian: null,
        jieshushijian: null,
        shichang: null,
        shangxingliuliang: null,
        xiaxingliuliang: null,
        zongliuliang: null,
        yuanip: null,
        mudiip: null,
        status: null,
        yuanduankou: null,
        mudiduankou: null,
        wangzhi: null,
        chexingmingcheng: null,
        queryNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      editDetails(id).then(response => {
        this.form = response.data;
        console.log('form', this.form);
        this.open = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除dataInfo编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 车辆详情 */
    showCXdialog(row) {
      this.cxDialogVisible = true
      getCarDetails(row.id).then(response => {
        this.carDetailsForm = response.data;
        this.code = response.code
        if(this.code !== 200) {
          this.cxDialogVisible = false
        }
      })
    },
  }
};


</script>

<style scoped>
.no-click {
  pointer-events: none;
  cursor: default;
}
</style>